#include "cJson/cJSON.h"
#include <stdlib.h>
#include "log/log.h"
int main(int argc, char const *argv[])
{
    //生成json
    char *name = "jim";
    int age = 18;
    cJSON *root = cJSON_CreateObject();
    cJSON_AddStringToObject(root,"name", name);
    cJSON_AddNumberToObject(root,"age", age);
    char *json = cJSON_Print(root);
    log_info("Generated JSON: %s", json);

    //解析json
    cJSON *parse_json = cJSON_Parse(json);
    if(parse_json == NULL) {
        log_error("Failed to parse JSON");
    }
    cJSON *name_obj = cJSON_GetObjectItem(parse_json, "name");
    cJSON *age_obj = cJSON_GetObjectItem(parse_json, "age");
    if(name_obj && age_obj) {
        log_info("Parsed name: %s", name_obj->valuestring);
        log_info("Parsed age: %d", age_obj->valueint);
    } else {
        log_error("Failed to get items from parsed JSON");
    }

    //释放资源
    cJSON_Delete(root);
    cJSON_Delete(parse_json);
    free(json);





    return 0;
}
